package org.testis.communication.client;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * A class used  to check  availability of hosts, for instance, 
 * that a requested service is not available or that a host or 
 * router could not be reached.
 * @author nurhat
 */
public class AtofIcmpClient
{

    /**
     * Checks a host if available according to given hostip.
     * As default it waits  host response for 10 seconds
     * @param hostIp
     * @return true if host is available
     * @throws java.io.IOException
     */
    public boolean isAvailable(String hostIp)
    {
        boolean result = false;

        try {
            result = InetAddress.getByName(hostIp).isReachable(10000);
        } catch (UnknownHostException ex) {
        } catch (IOException ex) {
        }
        return result;
    }


    /**
     * Checks a host if available according to given hostip, 
     * and  it waits  host response for given timeout value
     * @param hostIp
     * @param timeout
     * @return true if host is available
     * @throws java.io.IOException
     */
    public boolean isAvailable(String hostIp,
                               int timeout)  
    {
         boolean result = false;

        try {
            result = InetAddress.getByName(hostIp).isReachable(timeout);
        } catch (UnknownHostException ex) {
        } catch (IOException ex) {
        }
        return result;
       
    }
}
